#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
char str[maxn];
char p[6]={"#ANOT"};
LL cnt[5],res[5];
map<char,LL>map1;
int main(void){
   	cin.tie(0);std::ios::sync_with_stdio(false);
    map1['A']=1;map1['N']=2;map1['T']=3;map1['O']=4;
    LL t;cin>>t;
    while(t--){
        cin>>(str+1);LL n=strlen(str+1);
        memset(cnt,0,sizeof(cnt));
        for(LL i=1;i<=n;i++) cnt[map1[str[i]]]++;
        LL best=-1;string ans="";
        do{
           memset(res,0,sizeof(res));
           for(LL i=1;i<=4;i++) res[i]=cnt[map1[p[i]]];
           LL sum=0;
           for(LL i=1;i<=n;i++){
               for(LL j=1;j<=4;j++){
                   if(str[i]==p[j]){
                      res[j]--;
                      break;
                   }
                   else{
                      sum+=res[j];
                   }
               }
           }
            if(best<sum){
                best=sum;
                ans="";
                for(LL j=1;j<=4;j++) ans+=p[j];
            }
        }while(next_permutation(p+1,p+1+4));
        for(LL i=0;i<4;i++){
            for(LL j=1;j<=cnt[map1[ans[i]]];j++){
                cout<<ans[i];
            }
        }
        cout<<"\n";
    }
    return 0;
}
